package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_COMMENT;
import static xj.model.uml.UMLModelConstants.ATTR_CONSTRAINT;
import static xj.model.uml.UMLModelConstants.ROLE_ACTION;
import static xj.model.uml.UMLModelConstants.ROLE_EVENT;

public class InternalTransition 
  extends BasicModelElement {

  public InternalTransition() {
    this((Event) null, (Action) null);
  }

  public InternalTransition(String event, String action) {
    this(new Event(event), new Action(action));
  }

  public InternalTransition(Event event, Action action) {
    setEvent(event);
    setAction(action);

    destructable = false;
    preserved = true;
  }

  public Event getEvent() { 
    return event;
  }

  public void setEvent(Event event) {
    this.event = event;
    setOwnedElement(ROLE_EVENT, event);
  }

  public String getEventName() { 
    if (event != null) { 
      return event.getName(); 
    } else { 
      return null;
    }
  }

  public void setEventName(String eventName) {
    if (event == null) { 
      setEvent(new Event(eventName));
    } else { 
      event.setName(eventName);
    }
  }

  public Action getAction() {
    return action;
  }

  public void setAction(Action a) {
    action = a;
    setOwnedElement(ROLE_ACTION, action);
  }

  public String getActionName() { 
    if (action != null) { 
      return action.getName();
    } else { 
      return null;
    }
  }

  public void setActionName(String actionName) {
    if (action == null) { 
      setAction(new Action(actionName));
    } else { 
      action.setName(actionName); 
    }
  }

  public String getActionBody() { 
    if (action != null) { 
      return action.getBody();
    } else { 
      return null;
    }
  }  

  public void setActionBody(String actionBody) {
    if (action == null) { 
      setAction(new Action(null, null, actionBody));
    } else { 
      action.setBody(actionBody); 
    }
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    InternalTransition t = (InternalTransition) super.clone();
    if (event != null) { 
      t.setEvent((Event) event.clone());
    }
    if (action != null) { 
      t.setAction((Action) action.clone());
    }
    return t;
  }

  protected Event event;

  protected Action action;

}
